package com.putong35.common.httprequest.volleyadaptee;

import com.android.volley.NetworkResponse;
import com.android.volley.Response;
import com.android.volley.toolbox.JsonObjectRequest;

import org.json.JSONObject;

import java.util.HashMap;
import java.util.Map;

/**
 * JsonObjectRequest 的扩展
 *
 * @Author: PV
 * @E-mail: pengveivei@sina.cn
 * @CreateDate: 2016/7/21 11:09
 * @Version: 1.0.0
 */
public class XJsonObjectRequest extends JsonObjectRequest {
    private Map<String, String> mHeaderParams;
    public XJsonObjectRequest(int method, String url, JSONObject jsonRequest, Map<String, String> headParams, Response.Listener<JSONObject> listener, Response.ErrorListener errorListener) {
        super(method, url, jsonRequest, listener, errorListener);
        mHeaderParams = headParams;
    }

    @Override
    public Map<String, String> getHeaders() {
        HashMap<String, String> headers = new HashMap<String, String>();
        headers.put("Accept", "application/json");
        headers.put("Content-Type", "application/json; charset=UTF-8");
        if (mHeaderParams != null && mHeaderParams.size() > 0) {
            headers.putAll(mHeaderParams);
        }
        return headers;
    }

    protected Response<JSONObject> parseNetworkResponse(NetworkResponse response) {
        return ResponseHelper.parseNetworkResponse2JSONObject(response);
    }
}
